nedoPC.org

Electronics hobbyists community established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 28 Mar 2024 13:14



Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
[ZX] FZX: standard format and driver for proportional font 
Author Message
Fanat
User avatar

Joined: 29 Jan 2013 13:43
Posts: 52
Location: 86.182.165.70
Reply with quote
FZX is a very compact and efficient (although extremely flexible and powerful) standard format to create new fonts for the ZX-Spectrum. It supports proportional fonts, you can print characters anywhere on screen, and it's very easy to use in Sinclair BASIC, or called directly from Assembly routines.

The official FZX font format definition (including several sample fonts) is now available in FZX_Standard.zip, a tape file containing some practical examples is available in FZX.tap.zip, and the source code for the proportional printing driver is available in FZX_Driver.zip.

However let's skip all the tech details and go straight to the interesting stuff! Every character in a regular ZX-Spectrum font is designed using a 8x8 grid like this:

Image

But using FZX, each character definition is fully configurable and uses an arbitrary sized grid, like this:

Image

In the example above, the character pixels are defined in a smaller 5x5 grid, and everything else is configurable. This particular FZX font specifies that all characters are 9 pixels tall ("baseline"), character "a" is located at a distance of 2 pixels from the top ("leading"), character "a" is 5 pixels wide ("width"), and there should be 2 pixels of distance before the next character ("tracking").

All these configurations make it possible to define proportional fonts that are fully flexible and configurable, but still very compact, using about the same amount of memory as a regular font.

Now let's consider a practical example. This is the original Sinclair font:

Image

And here's the same text, using the same font style, but now converted to take advantage of FZX format using proportional spacing:

Image

Although it's the same font style and size, the latter version is more comfortable to read and doesn't take so much room on screen, so it's certainly an improvement!

Another nice feature of FZX format is that it supports quite large fonts, with characters up to 16 pixels wide. Here's another example, this time using a much larger font called "Grotesk" (also supplied in the link above):

Image

So how do you use FZX fonts in practice? It's actually very simple. First, load the driver from tape (together with any FZX font of your choice) and initialize it only once, like this:

Code:
CLEAR 59999: LOAD "Sinclair"CODE 60000: LOAD "FZXdriver"CODE 65000: RANDOMIZE USR 65000


Afterwards, simply use PRINT #4 to print your text, for instance:

Code:
PRINT #4;AT 0,0;"FZX driver code (c) Einar Saukas"'"FZX font format (c) Andrew Owen"
PRINT #4: FOR f=32 TO 127: PRINT #4;CHR$ f;: NEXT f


Using font "Zaibatsu" for instance (also supplied in this package), the program above will produce the following result:

Image

That's easy, right? :)

As indicated in the screen above, Einar Saukas and I have worked together to create FZX. I concentrated on defining the standard and designing the sample fonts supplied in this package, while he focused on coding it. Anyway everything presented here is open source and royalty-free, so you are welcome to use any of this material in your own programs (even commercial releases) and to create new FZX fonts yourself!


12 Jun 2013 00:55
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
I uploaded all images and files here

_________________
:dj: https://mastodon.social/@Shaos


Last edited by Shaos on 12 Jun 2013 14:50, edited 1 time in total.



12 Jun 2013 14:49
Profile WWW
Supreme God
User avatar

Joined: 21 Oct 2009 08:08
Posts: 7777
Location: Россия
Reply with quote
Post 
My special thanks! :kruto:

_________________
iLavr


12 Jun 2013 14:50
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
GREAT FONTS!

Source code of the printing driver:

Code:
; -----------------------------------------------------------------------------
; FZX driver - Copyright (c) 2013 Einar Saukas
; -----------------------------------------------------------------------------

        org     65000           ; driver address

FONT    EQU     60000           ; font address

MARGIN  EQU     0               ; left margin (in pixels)

STR_NUM EQU     4               ; stream #4


; -----------------------------------------------------------------------------
; CREATE CHANNEL AND ATTACH STREAM

DRIVER:
        ld      hl, ($5c53)     ; store system variable PROG in HL
        dec     hl
        ld      bc, 5           ; allocate 5 bytes for channel below BASIC area
        push    bc
        call    $1655           ; call routine MAKE-ROOM
        pop     bc
        ld      hl, CH_DATA + 4
        lddr                    ; copy CH_DATA to new channel space
        ld      hl, ($5c4f)     ; store system variable CHANS in HL
        ex      de, hl
        inc     hl
        inc     hl              ; now HL = allocated address + 1
        sbc     hl, de          ; calculate offset between start of channels
                                ;   area and start of the new channel space
                                ;   (notice the carry flag was already cleared
                                ;   from executing CALL $1655 earlier)
        ld      (STR_OFF), hl   ; attach stream by storing channel address
                                ;   offset in streams table
        ret

STR_OFF EQU $5c10+((STR_NUM+3)*2) ; address of channel offset in streams table

CH_DATA:
        defw    START           ; address of the PRINT # routine
        defw    $15c4           ; address of the INPUT # routine
        defb    'S'             ; channel type 'S'

; -----------------------------------------------------------------------------
; PROPORTIONAL PRINT ROUTINE

START:
        ld      hl, P_FLAG      ; initial address of local variables
        dec     (hl)            ; check P_FLAG value by decrementing it
        jp      m, CHK_AT       ; expecting a regular character?
        jr      z, GET_COL      ; expecting the AT column?
GET_LIN:
        cpl
        add     a, 192          ; now A = 191 - char
        inc     hl
GET_COL:
        inc     hl
        ld      (hl), a
        ret
CHK_AT:
        cp      22              ; specified keyword 'AT'?
        jr      nz, CHK_CR
        ld      (hl), 2         ; change P_FLAG to expect line value next time
        ret
CHK_CR:
        inc     (hl)            ; increment P_FLAG to restore previous value
        inc     hl
        ld      bc, FONT
        push    bc
        pop     ix
        cp      13
        jp      z, NEWLINE
CHK_CHAR:
        dec     a               ; now A = char - 1
        cp      (ix+2)          ; compare with lastchar
        jr      nc, UNDEF_CHAR
        sub     31              ; now A = char - 32
        jr      nc, PRINT_CHAR
UNDEF_CHAR:
        ld      a, '?'-32       ; print '?' instead of invalid character
PRINT_CHAR:
        inc     a               ; now A = char - 31
        ld      l, a
        ld      h, 0
        ld      d, h
        ld      e, l
        add     hl, hl
        add     hl, de          ; now HL = (char - 31) * 3
        add     hl, bc          ; now HL references offset/kern in char table
        ld      e, (hl)
        inc     hl
        ld      a, (hl)
        and     63
        ld      d, a            ; now DE = offset

        xor     (hl)
        rlca
        rlca
        ld      c, a            ; now C = kern

        push    hl
        add     hl, de
        dec     hl              ; now HL = char definition address
        ex      (sp), hl        ; now HL references offset/kern in char table
        inc     hl              ; now HL references shift/width in char table
        xor     a
        rld                     ; now A = char shift
        push    af
        rld                     ; now A = (width - 1)
        ld      (WIDTH1+1), a
        cp      8               ; check if char width is larger than 8 bits
        rld                     ; restore char shift/width

        ld      de, $000e       ; same as "LD C,0"
        jr      c, NARROW_CHAR
        ld      de, $234e       ; same as "LD C,(HL)" and "INC HL"
NARROW_CHAR:
        ld      (SMC), de       ; self-modify code to handle narrow/large chars

        inc     hl              ; now HL references next char offset
        ld      a, (hl)         ; now A = LSB of next char offset
        add     a, l
        ld      e, a            ; now E = LSB of next char definition address

        ld      hl, P_COL
        ld      a, (hl)
        sub     c               ; move left number of pixels specified by kern
        jr      nc, ON_SCREEN   ; stop moving if it would fall outside screen
        xor     a
ON_SCREEN:
        ld      (hl), a

        ld      a, (WIDTH1+1)   ; now A = (width - 1)
        add     a, (hl)         ; now A = (width - 1) + column
        call    c, NEWLINE      ; if char width won't fit then move to new line

        ld      bc, (P_COL)
        ld      a, 1
        sub     (ix+0)          ; now A = 1 - height
        add     a, b            ; now A = P_LIN - height + 1
        jp      nc, $0c86       ; call routine REPORT-5 ("Out of screen")

        pop     af              ; now A = shift

        add     a, 191          ; range 0-191
        call    $22aa + 2       ; call PIXEL-ADD + 2 to calculate screen address
        ex      af, af'
                                ; now A' = (col % 8)
        jr      CHK_LOOP

MAIN_LOOP:
        ld      d, (hl)         ; now D = 1st byte from char definition grid
        inc     hl              ; next character definition
SMC:
        ld      c, (hl)         ; now C = 2nd byte from char definition or zero
        inc     hl              ;   (either "LD C,0" or "LD C,(HL)" + "INC HL")
        xor     a               ; now A = zero (since there's no 3rd byte)
        ex      (sp), hl        ; now HL = screen address

        ex      af, af'
                                ; now A = (col % 8), A' = 0
        jr      z, NO_ROTATE
        ld      b, a            ; now B = (col % 8)
        ex      af, af'
                                ; now A = 0, A' = (col % 8)
ROTATE_PIXELS:
        srl     d               ; rotate right char definition grid in D,C,A
        rr      c
        rra
        djnz    ROTATE_PIXELS
NO_ROTATE:
        inc     l
        inc     l
        or      (hl)
        ld      (hl), a         ; put A on screen
        dec     l
        ld      a, c
        or      (hl)
        ld      (hl), a         ; put C on screen
        dec     l
        ld      a, d
        or      (hl)
        ld      (hl), a         ; put D on screen

        inc     h               ; move screen address by 1 pixel down
        ld      a, h
        and     7
        jr      nz, CHK_LOOP
        ld      a, l
        add     a, 32
        ld      l, a
        jr      c, CHK_LOOP
        ld      a, h
        sub     8
        ld      h, a
CHK_LOOP:
        ex      (sp), hl        ; now HL = char definition address
        ld      a, l
        cp      e               ; check if reached next char definition address
        jr      nz, MAIN_LOOP   ; loop otherwise

        pop     hl              ; discard screen address from stack
        ld      hl, P_COL
        ld      a, (hl)         ; now A = column
WIDTH1:
        add     a, 0            ; now A = column + (width - 1)
        scf
        adc     a, (ix+1)       ; now A = column + width + tracking
        jr      nc, EXIT        ; if didn't fall outside the screen then exit
NEWLINE:
        ld      (hl), MARGIN    ; move to initial column at left margin
        inc     hl
        ld      a, (hl)         ; now A = line
        sub     (ix+0)          ; now A = line - height
EXIT:
        ld      (hl), a         ; move down a few pixels specified by height
        ret

P_FLAG:
        defb        0
P_COL:
        defb        MARGIN
P_LIN:
        defb        191

; -----------------------------------------------------------------------------


P.S. Also what is the license of actual fonts? Royalty free?
Code:
Chloe 8pt Bold
copyright (c) 2013 Andrew Owen
- a narrow monospaced font designed for CRT displays

Geneva 9pt Roman by Susan Kare
copyright (c) 1984 Apple, Inc.
- a Swiss style sans-serif font

Grotesk 24pt Condensed Bold
copyright (c) 2013 Andrew Owen
- a headline font inspired by Hermann Zapf

Lettera 10pt Roman
copyright (c) 2013 Andrew Owen
- a monospaced font inspired by Olivetti typewriters

Sabon 16pt Roman OSF
copyright (c) 2013 Andrew Owen
- a serif font inspired by Jan Tschichold

Sinclair 9pt Roman by Steve Vickers
copyright (c) 1982 Amstrad, plc.
- a proportional version of the Spectrum system font

Soxz 7pt Roman
copyright (c) 2013 Andrew Owen
- a small system font

Zaibatsu 9pt Bold
copyright (c) 2013 Andrew Owen
- a futuristic font


P.P.S. Word "Zaibatsu" looks very much as Russian equivalent of "f*cking awesome" ;)

_________________
:dj: https://mastodon.social/@Shaos


12 Jun 2013 15:24
Profile WWW
Fanat
User avatar

Joined: 29 Jan 2013 13:43
Posts: 52
Location: 86.182.165.70
Reply with quote
Post 
The license for the fonts I designed is royalty free. You can use them as long as you don't modify them. An acknowledgement would be nice but is not required.

At some point I'll probably develop Sabon and Grotesk to include a full suite of fonts, including accents, small caps, and Cyrillic. I just don't have a heap of time to work on it right now. I'm also waiting for Claus Jahn to create an editor so I don't have to do all the work in an assembly file.

The Sinclair font is the example file so you can basically do what you like with it.

The Geneva font is copyright Apple and you should probably get permission from them to use it. On the other hand if you don't they probably won't notice.

Zaibatsu is a Japanese word. The meaning is roughly "mega corporation".


13 Jun 2013 00:27
Profile
Banned
User avatar

Joined: 20 Mar 2005 13:41
Posts: 2141
Location: От туда
Reply with quote
Post 
cheveron wrote:
Zaibatsu is a Japanese word. The meaning is roughly "mega corporation".

Japanese - such gourmets. :3


13 Jun 2013 00:33
Profile
Fanat
User avatar

Joined: 29 Jan 2013 13:43
Posts: 52
Location: 86.182.165.70
Reply with quote
Post 
So, an update. Three editors should be available soon on Windows, Mac, and Linux respectively. I have absolutely nothing to do with these efforts but I'll post the links when I get them.


20 Jun 2013 16:05
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
cheveron wrote:
So, an update. Three editors should be available soon on Windows, Mac, and Linux respectively. I have absolutely nothing to do with these efforts but I'll post the links when I get them.


font editors?

_________________
:dj: https://mastodon.social/@Shaos


20 Jun 2013 18:26
Profile WWW
Fanat
User avatar

Joined: 29 Jan 2013 13:43
Posts: 52
Location: 86.182.165.70
Reply with quote
Post 
Shaos wrote:
font editors?


Yes. There's a brand new FZX editor from Claus Jahn for Windows, a module for RoboFont for the Mac, and an FZX export option for gbdfed for Linux. None of them are ready yet.

Also, Einar has converted all the fonts that appeared with the Czech program Desktop (which is now public domain apparently):

DesktopFZX.zip (48493 bytes)

DesktopFontEditorFZX.zip (22477 bytes)


21 Jun 2013 00:23
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
It should be relatively easy to create font converter for Windows that may convert any vector font from Windows to FZX with rasterization to proper size

P.S. I moved your archives to our upload folder

_________________
:dj: https://mastodon.social/@Shaos


22 Jun 2013 07:01
Profile WWW
Fanat
User avatar

Joined: 29 Jan 2013 13:43
Posts: 52
Location: 86.182.165.70
Reply with quote
Post 
Shaos wrote:
P.S. I moved your archives to our upload folder


You might want to add Einar's latest set too:

DesktopKud1FZX.zip (38027 bytes)


27 Jun 2013 23:48
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
cheveron wrote:
Shaos wrote:
P.S. I moved your archives to our upload folder


You might want to add Einar's latest set too:

DesktopKud1FZX.zip (38027 bytes)


Thanks

P.S. I reupload your file here again ;)
Mediafile has really disturbing advertizing practices as new windows with fishy texts...

_________________
:dj: https://mastodon.social/@Shaos


28 Jun 2013 00:00
Profile WWW
Fanat
User avatar

Joined: 29 Jan 2013 13:43
Posts: 52
Location: 86.182.165.70
Reply with quote
Post 
Shaos wrote:
Mediafile has really disturbing advertizing practices as new windows with fishy texts...


Not sure why Einar uses it. I just use DropBox.


29 Jun 2013 18:35
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
cheveron wrote:
Shaos wrote:
Mediafile has really disturbing advertizing practices as new windows with fishy texts...


Not sure why Einar uses it. I just use DropBox.


Ask him to register here - we will be more than happy to host his files ;)

_________________
:dj: https://mastodon.social/@Shaos


29 Jun 2013 19:04
Profile WWW
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
FZX Editor 0.952 for Windows

Attachment:
fzx_editor.jpg
fzx_editor.jpg [ 77.65 KiB | Viewed 11488 times ]

https://www.spectrumforeveryone.co.uk/technical/zx-modules-software/

P.S. Link fixed and image uploaded right here in April 2021

P.P.S. Link changed again in January 2023

_________________
:dj: https://mastodon.social/@Shaos


03 Jul 2013 17:52
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.