XFont Text Render Library [v11.9.13]

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
Leonheart
Posts: 82
Joined: Nov 20, 2007 9:08
Contact:

Post by Leonheart »

Sorry,, sorry...

I'm just start to working with the libs again today after tiresome months....
Not promise...
but,
Lets see what is next :D
Leonheart
Posts: 82
Joined: Nov 20, 2007 9:08
Contact:

Post by Leonheart »

Kwabbernoot: refer to documentation,

for 1, 2, 4 and 8 bpp mode, forecolor use AAAAAAAAXXXXXXXXXXXXXXXXPPPPPPPP as color format.
Where AAAAAAAA is foreground masking flag, and PPPPPPPP is palette color index.
Set AAAAAAAA value < 128 will passed foreground drawing.
Tips : To make backgound appear is possible to set foreolor expression with palette or &hFF000000.

Here is modification for your code:

Code: Select all

#Include Once "xfont.bi"
Dim Shared As xfont.interface font

Dim As Short ani
Dim As Byte flg = 1

'Screen 18,32
   ScreenRes 800, 600, 8

While Len(Inkey) = 0
    ScreenLock()
    Cls
'   font.backcolor = Rgba(255,255,0,255-ani)
'   font.forecolor = Rgba(255,0,0,ani)
    font.backcolor = 0
    font.forecolor = 14 Or &hFF000000
'   font.drawstring(,"Hello world", 100, ani+100,,,1)
    font.drawstring(,"Hello world", 100, ani+100, 2, 2,1)
        
    font.backcolor = 0
    font.forecolor = 3 Or &hFF000000
'   font.forecolor = Rgba(0,0,255,255-ani)
'   font.drawstring(,"Hello world", 150, 355-ani)
    font.drawstring(,"Hello world", 150, 355-ani, 2, 2)
    
'   font.forecolor = Rgba(0,255,0,255-ani)
    font.forecolor = 10 Or &hFF000000
    font.drawstring(,"Hello world", 150, 355-ani, 255/(ani+10),255/(ani+10))
    
    ani+=flg
    If ani=255 Then flg =-1
    If ani=0 Then flg =1
    
    ScreenUnlock()
    Sleep 50
Wend
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Re: XFont Text Render Library [Last version 25 August 2011]

Post by 1000101 »

Hey Leonheart,

I've been using xFont for a couple things but there is one thing which I find problematic - clipping. While the renderer does clip to the main system clipper it would be nice to be able to force a clipping region to it specifically for easier use with rendering to a buffer target. Is there any chance of this being added or getting a copy of the library source to make changes to the code directly?
Leonheart
Posts: 82
Joined: Nov 20, 2007 9:08
Contact:

Re: XFont Text Render Library [Last version 13 Sept 2011]

Post by Leonheart »

Many people asking for the source, fix, feature, mod, etc.
Also I still don't have time yet to change the lib to use small memory only.
Since 1000101 asking me (Wow! I'm so afraid moderator/admin/op will make something fishy. They will kick, punch, kill, ban me, etc), I decide to make it open source. ^^!
Ok, I will like to see what changes you will made Eric. ;p

source

Sorry for bad programming style if it occurs.

btw, why with this forum (new look) I can't edit my post again??
VANYA
Posts: 1837
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: XFont Text Render Library [Last version 13 Sept 2011]

Post by VANYA »

Leonheart wrote:Many people asking for the source, fix, feature, mod, etc.
Also I still don't have time yet to change the lib to use small memory only.
Since 1000101 asking me (Wow! I'm so afraid moderator/admin/op will make something fishy. They will kick, punch, kill, ban me, etc), I decide to make it open source. ^^!

Thanks!
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Re: XFont Text Render Library [Last version 25 August 2011]

Post by Richard »

@ Leonheart.
You should be able to edit your previous posts. You must be logged on to get an edit box.
(Wow! I'm so afraid moderator/admin/op will make something fishy. They will kick, punch, kill, ban me, etc)
The moderators are your friend, they are here to help you. What do you need ?
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Re: XFont Text Render Library [Last version 25 August 2011]

Post by 1000101 »

Just to note, I don't moderate the forum, just the irc channel. Anyway, thanks for the source release. Also, none of the moderators would take any negative action if you wanted to keep it closed source. You have your rights to your intellectual property after all.
Leonheart
Posts: 82
Joined: Nov 20, 2007 9:08
Contact:

Re: XFont Text Render Library [Last version 25 August 2011]

Post by Leonheart »

Just kidding XD
It is now open source. Public have it :'p

@Richard:
I'm sorry, I turned off image display in browser before. Now I can see the box. Hehehe
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Re: XFont Text Render Library [v11.9.13]

Post by 1000101 »

So, after a couple weeks of code changes I've made some significant changes to the library.

Changes:
1) Created FbEdit project file;
2) 1 instance x 10 fonts -> 1 instance per font;
3) Updated to full class based code style (use new/delete);
4) Massive code body changes (multiple modules with specific functionality) allowing for smaller executables (only used functions are included in the resulting executable);
5) Backend render method changed from one render function per color mode and rotation to one render function per rotation and an optimized non-scaled renderer per rotation;
6) Pixel blitting is now done as a backend function which handles blending and translation to the target color mode.
7) Added a forced clipping regions for buffer blitting (buffers don't use the screen clipper);
8) Smooth scaling by interpolation of "missing" pixels in the font data. This does make the scaling slower but it looks nicer, it also makes fonts look "correct" when scaling <1.0;
9) Removed individual x/y scaling to one single scale.

Todo:
1) Update scaled rotation mode 1, 2, 3 code to utilize interpolation;
2) Put "block scale" modes back in for faster scaled rendering.

Aside from font instantiation the usage has not changed (exception of scale value(s)).

If anyone wants what I've done so far then I will upload it somewhere but don't expect me to rush to fix the rotation code (it's not tested). I only worked towards getting the "0" rotate code working (since it's the most important).

default
Image
freesans
Image
Leonheart
Posts: 82
Joined: Nov 20, 2007 9:08
Contact:

Re: XFont Text Render Library [v11.9.13]

Post by Leonheart »

Wheeew,,, O.O!?
Very.... Great... Awesome....

Maybe I should stab myself with katana
Lord Bane
Posts: 2
Joined: Jul 10, 2010 4:10

Re: XFont Text Render Library [v11.9.13]

Post by Lord Bane »

If anyone wants what I've done so far then I will upload it somewhere but don't expect me to rush to fix the rotation code (it's not tested). I only worked towards getting the "0" rotate code working (since it's the most important).
I would be interested.

Thank you.
Kwabbernoot
Posts: 80
Joined: Apr 19, 2010 18:23
Location: NL

Re: XFont Text Render Library [v11.9.13]

Post by Kwabbernoot »

Anybody any idea how to create a font?
It seems that you need the conversion program: xfconv.exe.
The conversion program shows two buttons: save and load. But load what??
Also no idea what input fields "aliased" and "message" means.
I want the font Courier New size 12.
But how to create it??
ReeVee
Posts: 1
Joined: Oct 21, 2012 18:47

Re: XFont Text Render Library [v11.9.13]

Post by ReeVee »

At the top of the converter click Browse this will let you set the location to save the font file and set the file name. Browse and Set the directory to the same directory where you program file is. Type in the name for you font file, the file extension will be added automatically. I name fonts like this font_fontname_size for ease of identification so you might use font_Courier_New_12 or whatever works best for you. Select the "Text Font" and "Size" you want from the drop downs and check any option boxes you want (bold,Italic,Underline). Click "Convert" and the .fx font file will be saved to the specified directory and file name. If you want to create fonts in more than one style or size just change you settings edit the file name accordingly and Convert. Vary easy to create a font assortment that way.
Kwabbernoot
Posts: 80
Joined: Apr 19, 2010 18:23
Location: NL

Re: XFont Text Render Library [v11.9.13]

Post by Kwabbernoot »

Okay, that's the right order. Simple. You have to click on "convert", I did click "save".
Thank you very much ReeVee.
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Re: XFont Text Render Library [v11.9.13]

Post by BasicScience »

@ Lionhart,

I came across a bug in xFont. The LoadFont function will close file number 1, which can be a problem if the main program has another file assigned to number 1. The LoadFont function does use FF = FreeFile, and reads from #FF... but then accidentally closes #1

Section of code posted below.

Code: Select all

Function Interface.LoadFont Overload (ByRef Filename As String, ByVal FontIdx As uByte) As Integer 
    'Akan mengembalikan _False_ Jika berhasil, dan _True_ jika tidak
            'Dim As String fname = filename
            Dim As Integer FF
            Dim As uInteger FL
            Dim As uByte Ptr MyPtr
            Dim As uByte tmpHeader(444)
            Dim As XFONT_HEADER retHeader 
            Dim As Integer ret
            'Print fname
            
            If (FontIdx < 1) Or (FontIdx > MAX_SLOT) Then  LastErrorCode = IndexOutOfBound : Return _True_   
            If FontCollection(FontIdx).Loaded Then LastErrorCode = InvalidHandle : Return _True_ 'Font already used
            
            If Not FileExists(Filename) Then LastErrorCode = FileNotFound : Return _True_
            FL = FileLen(Filename)
            If FL <= 445 Then LastErrorCode = InvalidFileSize : Return _True_     'Size to small
            
            'Read header
            FF = FreeFile
            Open Filename For Binary As #FF 'Len=1
            Get #FF,1,tmpHeader()
            retHeader = CreateCompatibleHeader(@tmpHeader(0))
            If QueryHeaderCompat(retHeader, FL) Then  'Checking Header
                Close #FF
                LastErrorCode = InvalidHandle : Return _True_    
            End If
            
            FL = retHeader.DataOffset+retHeader.DataLength
            MyPtr=Allocate(FL)
            Get #FF,1,*MyPtr,FL
            Close #1
            ret= Backend_LoadFont(MyPtr, FL, FontIdx)                            'LoadFont
            Deallocate(MyPtr)
            Return ret
    End Function    
Post Reply