flat assembler
Message board for the users of flat assembler.

Index > Heap > Some font converter?

Author
Thread Post new topic Reply to topic
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
Hello,
Well can anyone point me out to some program that can convert TrueType Fonts (lol) to VGA 8x16 (80x25 text Razz) font.
-s8d123

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD
Post 12 Mar 2014, 08:47
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 724
tthsqe
I use mathematica for this. Would you like me to convert something for you?
Post 12 Mar 2014, 09:07
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
Wolfram Alpha Mathematica?
Lol, but it would be of great help if Ubuntu Mono or something similar could be converted (maybe the request is too high?). Is Mono proprietary?

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD
Post 12 Mar 2014, 09:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17248
Location: In your JS exploiting you and your system
revolution
You can write a small program in Windows to print each character (DrawText) to a memory buffer and save the BMP to disk.

Or even use paint to manually write out the alphabet in the desired size and spacing and use prnt-scrn to save as a BMP.
Post 12 Mar 2014, 09:50
View user's profile Send private message Visit poster's website Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 724
tthsqe
But It is clear that he/she does not want to do this by hand.
Sid, I was talking about the flow blown version, not wolframalpha.
I already have a setup for converting fonts to bitmaps, I would just need know what font you want to convert, and how you would like the bitmaps for each characters organized into a file (and how store the pixel data, ect..).

EDIT: does http://wiki.osdev.org/VGA_Fonts describe the format for eaxh charater? Then, for example the 'A' character would be stored at offset +16*66 in the file? Also, as for your proprietary concerns, if you only have 8 bits for the width of the character, how could any one tell that is from a given font family?
Post 12 Mar 2014, 10:23
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
To what format? 8x16 binary? My fonts use a "variant" scanline (DRAW.INC) to simulate clear-type in high-resolution fonts. Smaller fonts (<=16 H) should be pure binary, 1/0. The font image containing all glyph symbols may be stored in an external file or inside of the executable (file 'my.bmp'). You just have to know the file format (.TGA is easy) and how to draw an array of pixels. Algorithms:

Draw character in ARM (RGB16) and X86 (RGB32) (FONT.INC):
Code:
; draw a1=character, a2/a3=x/y, a4=color

function draw.c, ch, x, y, c
  alias c=a1, p=v1,\
   x=v2, y=v3,\
   fw=v4, fh=v5,\
   fwb=v6, fc=v7
  . x=a2, y=a3, fc=a4   ; save these
  . p=FONT.SYMBOLS, p+c ; symbols[c]
  . (i8) c=*p
  .if c=63              ; invisible
    return
  .end
  . p=font              ; p=&image[s[c]*fw*2]
  . fw=FW, c*fw, c<<1
  . p=p->image.p, p+c
  . fwb=FIW, fwb<<1     ; image.w in bytes
  . fh=FH               ; draw font.h
  .repeat fh            ; # scanlines
    pusha
    draw.scanline.v \
     x, y, fw, fc, p
    popa
    . p+fwb, y++        ; advance p/y++
  .endr
endf

; draw.c 'Z', 1, 1

function draw.c, c, x, y
  locals p, iw, i, n
  . r0=FONT_SYMBOLS, r0+c

  if byte [r0]=63 ; invisible?
    return
  end
  try visible? x, y, [font.w], [font.h]

  ; p=&image[symbols[ch]*font.w*4]

  . r0=FONT_SYMBOLS, r0+c,\
   r0=>[r0], r0*[font.w], r0<<2,\
   r0+[font.image.p], p=r0,\
   iw=[font.image.w], iw<<2

  ; draw font.h # scanlines

  loop i=0 to [font.h]
    . r1=y, r1+i
    draw.scanline.v p, x, r1,\
     [font.w], [font.color]
    . r1=p, r1+iw, p=r1
  endl
endf    
Draw text in ARM and X86:
Code:
; draw.text t=a1, x=a2, y=a3, color=a4

function draw.text
  alias t=v1,\        ; aliases
   x=v2, y=v3,\
   c=v5, fw=v6, ix=v7
  . t=a1, x=a2, y=a3  ; save these
  . ix=x, fw=FW       ; x, font w
  . (u8) c=*t
  .while c            ; while nonzero
    . (u8) c=*t++     ; get next c
    .if c=0Dh         ; return?
      . t++, x=ix     ; skip 0Ah after
      . x-fw, y+FH    ; reset x/y
    .end
    draw.c c, x, y    ; draw character
    . x+fw            ; x+font.w
  .endw
endf

; draw.text.t 'Example', 1, 1

function draw.text, t, x, y
  locals i, n, p
  . r0=t, p=r0, i=0
  while byte [r0]       ; draw all characters
    . r1=i,\            ; x=i*font.w+x
     r1*[font.w],\
     r1+x, r0=p,\       ; get c
     r0=>[r0]
    if r0=0Dh           ; return?
      . i=0,\           ; reset x
       r1=[font.h],\
       y+r1, p++        ; y+font.h
      jmp .next
    end
    . r2=y, r2-[font.h] ; get y-font.h
    if r2>[screen.h]    ; off screen?
      return
    end
    draw.c r0, r1, y    ; draw character
    . i++
    .next:
    . p++, r0=p         ; r0=p for while
  endw
endf    
Post 12 Mar 2014, 11:40
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
Yes, almost all outline fonts are proprietary / copyrighted. Heck, I'm not even 100% convinced that old raster fonts are truly uncopyrightable. (Even if that were reliably true, the laws probably changed.) Fonts are an incredibly big business (see Adobe). Sure, there are some Linux fonts that are free (e.g. open font license 1.1), but no, I don't think you can just grab whatever you want to use with impunity.

Having said that, the only reason I know any of this is because I dabbled investigating this a few months ago, for fun, for the sake of FreeDOS (not that anybody asked).

http://ftp.ibiblio.org/pub/micro/pc-stuff/freedos/files/util/system/fonts/

There was a guy (1999? 2001?) who wrote two font programs for FreeDOS, and they have been included in "UTIL" ever since: LOADFONT (aka, GNUCHCP [horribly confusing name]) and TTF2FNT.

The problem is that they weren't even mirrored properly (until I very recently fixed that!), plus had some unknown fonts (license???), plus TTF2FNT is a Win32 GUI (Delphi 3) program!

http://www.freedos.org/software/?prog=loadfont
http://www.freedos.org/software/?prog=ttf2fnt

So, I don't know much more than that. Well, I rewrote the first, for fun, in assembly (cf. TP [non-free!]). It was exceedingly simple, just called the BIOS. But the other I left alone: I don't have Delphi (and no interest in Win32).

Oh, I did create my own lousy font via 2L8 (Fonte). Then I found Terminus and manually converted that via scripts, which is much better.

P.S. IIRC, I weakly tried TTF2FNT with only one font (Unifont?), and it didn't work. No idea if it will compile with FPC (doubt it), but you could try to tweak it, if desperate (GPL!).
Post 12 Mar 2014, 11:56
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
m3ntal wrote:
To what format? 8x16 binary? My fonts use a "variant" scanline (DRAW.INC) to simulate clear-type in high-resolution fonts. Smaller fonts (<=16 H) should be pure binary, 1/0.


Yes, for the record, I converted Terminus to "db 00001111b" style, ready to be assembled by FASM!
Post 12 Mar 2014, 12:00
View user's profile Send private message Visit poster's website Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
@rugxulo: Yep, I've seen that font, and I've used a lot of times. I guess Unix bdf2hex may be the answer.

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD
Post 12 Mar 2014, 12:14
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
My custom CODEX font is similar to Bitstream Vera and Consolas. There are many variations of these fonts that have little or no differences.
Quote:
I converted Terminus to "db 00001111b" style, ready to be assembled by FASM!
I use this technique on old game consoles (NES, Genesis/MD). For big fonts, it is faster to assemble the file of db's to binary then: file 'font.bin'
Post 12 Mar 2014, 14:05
View user's profile Send private message Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 340
Location: Asia, Singapore
sid123
Mind telling me the trick? Razz
Post 12 Mar 2014, 14:48
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
Make or find a program that converts the font .BMP to pure binary. Or save the .BMP as 1BPP monochrome then copy the bytes from a hex editor (HxD). Pixels should begin at 3Eh after the header and 8 byte palette (2 32BPP RGBs) until end of file.
Post 12 Mar 2014, 15:21
View user's profile Send private message Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
You'll need a font image and a look-up table to translate ASCII characters to glyph indices:


Description:
Filesize: 53.66 KB
Viewed: 3593 Time(s)

fontview.jpg


Post 12 Mar 2014, 15:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.