SRL Archive - Unofficial Development

Auto-Updating fonts?!


Gu3st...

2010-12-07 18:58:35

Easy & Quick method of updating fonts!

As some of you know, OpenGL can be used to extract the RuneScape font as a single .png file:


Each time JaGeX deciedes to update their fonts, we go bananas and our OCR would be down for a day or two because it's kinda hard to update the fonts using our current method (which is manually grabbing each and every character we can find).
Now we don't have to do that anymore. Why not?

By using OpenGL and Simba, we can now automatically update the fonts in matter of seconds after RuneScape updates. All we need to do is to have a program hook RuneScape and get the fonts we need (like the ones I've added further up in this post). Once we have done that, we can then 'chop' this image into smaller cells.

type
TCharSet = record
Path : String;
BMP : Integer;
Characters : array [0..255] of Integer;
Spacing : TPoint;
end;

const
FONT_PATH = '';

CHARSET_HIGH = 0;

var
CharSet : array [0..CHARSET_HIGH] of TCharSet;

function GetSpacing(var Bitmap : Integer) : TPoint;
var
W, H : Integer;
begin
GetBitmapSize(Bitmap, W, H);
Result := Point(W div 16, H div 16);
end;

procedure LoadCharsets;
var
I : Integer;
begin

for I := 0 to CHARSET_HIGH do
begin
with CharSet[I] do
begin

Path := FONT_PATH + IntToStr(I) + '.png';
if FileExists(Path) then
BMP := LoadBitmap(Path)
else
begin
WriteLn(FONT_PATH + IntToStr(I) + '.png, does not exist!');
TerminateScript;
end;
Spacing := GetSpacing(BMP);

end;
end;

end;

procedure ExtractCharacters;
var
I, C,
W, H,
X, Y, sX, sY,
Col, t : Integer;
begin

for I := 0 to CHARSET_HIGH do
begin
t := GetSystemTime;
GetBitmapSize(CharSet[I].BMP, W, H);
for C := 0 to 255 do // Extended ASCII Table.
begin
CharSet[I].Characters[C] := CreateBitmap(CharSet[I].Spacing.X, CharSet[I].Spacing.Y);
FastDrawClear(CharSet[I].Characters[C], clBlack);
for Y := 0 to CharSet[I].Spacing.X-1 do
for X := 0 to CharSet[I].Spacing.Y-1 do
begin
sX := ((C mod CharSet[I].Spacing.X)*CharSet[I].Spacing.X) + X;
sY := ((C div CharSet[I].Spacing.Y)*CharSet[I].Spacing.Y) + Y;
try
Col := FastGetPixel(CharSet[I].BMP, sX, sY);
FastSetPixel(Charset[I].Characters[C], X, Y, Col);
except end;
end;
end;
WriteLn(GetSystemTime - t);
end;

end;

procedure SaveCharacters;
var
I, J : Integer;
begin
if not DirectoryExists(FONT_PATH + 'Extracted') then
CreateDirectory(FONT_PATH + 'Extracted');
for I := 0 to CHARSET_HIGH do
begin
if not DirectoryExists(FONT_PATH + 'Extracted\' + IntToStr(I)) then
CreateDirectory(FONT_PATH + 'Extracted\' + IntToStr(I));
for J := 0 to 255 do
SaveBitmap(CharSet[I].Characters[J], FONT_PATH + 'Extracted\' + IntToStr(I) + '\' + IntToStr(J) + '.bmp');
end;
end;

procedure FreeCharsets;
var
I, J : Integer;
begin
for I := 0 to CHARSET_HIGH do
begin
FreeBitmap(CharSet[I].BMP);
for J := 0 to 255 do
FreeBitmap(CharSet[I].Characters[J]);
end;
end;

begin
LoadCharsets;
ExtractCharacters;
SaveCharacters;
FreeCharsets;
end.
Using this script, I've been able to turn the RuneScape UpText into a folder in only 3 seconds, and we might be able to make it even faster.
This is the images the script produced (put into a .rar file for easier uploading/downloading):
UpText, ChatChars or XPChars

Unfortunately we can't use those images just yet, as we have to trim those images a little more before Simba is able to handle them, but that would not be a big problem at all.

HOW-TO: Using the script:
First you have to create a folder named something like "Charsets", once you have done that, fill in the path to that folder into FONT_PATH. In my case it would be "C:\Users\User\Pictures\SRL\Charsets".
Next you download this image:
Save it as "0.png" inside the newly created folder.

Now you're done! Hit the run button and wait for the script to finish, then look inside your Charsets folder :)

EDIT: Now this script doesn't produce bmps with different widths like we use in Simba, but it will be fairly easy to alter the bmps (using a script) to match the ones we're using with simba today.
EDIT2: I'll do that ^ in the weekend.

Camaro'

2010-12-07 19:01:45

Nice job! Repped!

You deserve 100 reps for this post :)

Gu3st...

2010-12-07 19:19:06

[QUOTE=Camaro';756457]Nice job! Repped!

You deserve 100 reps for this post :)[/QUOTE]Hahaha thanks mate :)

EDIT: Now I got 5 rep balls :P thanks :D

Method

2010-12-07 19:25:36

I can dump the fonts from the cache if you guys would like. Here's one I did pretty quickly with the three (I think there are only three) fonts. Let me know if you need something different.

http://www.mediafire.com/?8f11f0xu55hlq1y

Wanted

2010-12-07 19:28:29

Unfortunately this does not fully solve the spacing problem (yet)

Gu3st...

2010-12-07 19:30:23

That too could be used, Method! :)
How did you do that? Using Java?
The problem right now is to make the fonts go hand in hand with Simba's font. As it is now, Simba has different widths for each bmp (Which imho is an easy problem to fix).

I'll be off to bed now, but I'll check this thread tomorrow to answer any questions (if there is any)

EDIT: Wait a few days James, and you'll see ;)

Method

2010-12-07 19:31:36

From: Zyt3x
That too could be used, Method! :)
How did you do that? Using Java?
The problem right now is to make the fonts go hand in hand with Simba's font. As it is now, Simba has different widths for each bmp (Which imho is an easy problem to fix).

I'll be off to bed now, but I'll check this thread tomorrow to answer any questions (if there is any)


Yes, I wrote a program that can load data from the cache into some of the different internal formats Jagex uses.

Sir R. M8gic1an

2010-12-07 20:23:13

Nice cup you got there mate!

Also, would you mind posting the OpenGL stuff in the Development Lounge? I'm about to make an OpenGL Forum there ;)

~RM

Wizzup?

2010-12-08 06:03:09

From: IceFire908
Unfortunately this does not fully solve the spacing problem (yet)


To my knowledge the spacing is only relevant for the actual generation of a bitmap for ``FindText''; Simba's OCR doesn't use spacing of the bitmaps. That is if I recall correctly, but I'm fairly sure.

Gu3st...

2010-12-08 10:04:02

From: Sir R. Magician
Nice cup you got there mate!

Also, would you mind posting the OpenGL stuff in the Development Lounge? I'm about to make an OpenGL Forum there ;)

~RM
Oh wow!! Thanks!!! :D

Will do! I am so glad you added an OpenGL subforum! I am really looking forward to doing some more OpenGL hooking :)

TomTuff

2010-12-08 10:06:20

It's sad that this has been posted 3 times (at least) before, yet this is the first time it's getting any attention.

Gu3st...

2010-12-08 10:46:01

From: TomTuff
It's sad that this has been posted 3 times (at least) before, yet this is the first time it's getting any attention.
Links?
I think this is the first time someone makes a script to update the fonts though..

EDIT:
From: Wizzup?
To my knowledge the spacing is only relevant for the actual generation of a bitmap for ``FindText''; Simba's OCR doesn't use spacing of the bitmaps. That is if I recall correctly, but I'm fairly sure.

Does this mean that Simba could use bmps like this for it's OCR: ?

Narcle

2010-12-08 12:20:20

From: Zyt3x
Does this mean that Simba could use bmps like this for it's OCR: ?


I think so? You'd just have to increase the height and min/max spacing parameters in the function call.

Wizzup?

2010-12-08 12:37:46

From: Zyt3x
Links?
I think this is the first time someone makes a script to update the fonts though..

EDIT:

Does this mean that Simba could use bmps like this for it's OCR: ?


Yes. Simba truncates the bitmap fonts anyway. It only remembers the values it has truncates for the CreateBitmapFromText stuff. I'm not sure if it is as trivial as this, but it is surely possible.

Wanted

2010-12-08 13:35:19

To my experience, the width of the bitmaps has been absolutely essential.

Shuttleu

2010-12-08 13:51:23

had an idea on how to make this fully auto

have it so it searches for the white, if it does it gets as close to the char as it can, so l will just be one line of pixels, basicly the left and right would have no pixels

then when it searches for it, you can set the min spacing and max spacing when you go searching for it

~shut

Method

2010-12-08 14:06:40

Has anyone tested out the characters I uploaded? They all have the same dimensions, but I wouldn't know if they need to be spaced out any differently.

Sir R. M8gic1an

2010-12-08 14:23:56

From: TomTuff
It's sad that this has been posted 3 times (at least) before, yet this is the first time it's getting any attention.


silentwolf was auto-memberized for it.

It got no attention? huh?

Method, I don't think anyone started any testing on the fonts just yet

~RM

Gu3st...

2010-12-08 17:27:23

From: Shuttleu
had an idea on how to make this fully auto

have it so it searches for the white, if it does it gets as close to the char as it can, so l will just be one line of pixels, basicly the left and right would have no pixels

then when it searches for it, you can set the min spacing and max spacing when you go searching for it

~shut
I already made it do that :)
Those letters (Srl) were made by the script. The problem is with characters such as " ' ^ and so on

n3ss3s

2010-12-11 13:34:13


have it so it searches for the white, if it does it gets as close to the char as it can, so l will just be one line of pixels, basicly the left and right would have no pixels


No, SplitTPA son, I think 2 as max space would work for every character (ones with accent marks and i).

Markus

2011-11-22 09:41:22

Ping. This is useful.

Method

2011-11-22 10:34:46

From: Markus
Ping. This is useful.


Are there any requirements for the fonts (spacing, background color, symbol color, etc.)? pyroryan asked me about fonts the other day, and I'm able to grab the images for every character in every font (including some obscure ones like the fairy language font).

Wizzup?

2011-11-22 10:37:26

To succesfully use CreateBitmapFromText and others, you'll need the correct spacing. There's probably a rule that you can generalize for that though. (e.g. if you have them without spacing, add a space on all sides…)

For the actual rs_GetUpTextAt, all spacing in the bitmaps is disregarded.

Method

2011-11-22 11:05:23

From: Wizzup?
To succesfully use CreateBitmapFromText and others, you'll need the correct spacing. There's probably a rule that you can generalize for that though. (e.g. if you have them without spacing, add a space on all sides…)

For the actual rs_GetUpTextAt, all spacing in the bitmaps is disregarded.


I can look into that later, but here are the fonts from the latest cache, if they are of any use. Each image in a font has the same size for the moment. I've also labeled the three core fonts with the names the client uses to identify them.

Wizzup?

2011-11-22 11:09:11

I guess it would be p12_full?

E: Confirmed p12_full

YoHoJo

2011-11-22 15:02:11

Anyone working on getting fonts?
Any way people can help?
We should make a font help/work on page so ppl can post bmps of fonts for everyone to mask or however we do it.

Wizzup?

2011-11-22 15:08:00

See Method's post. But I agree, we need a new topic for this.

YoHoJo

2011-11-22 15:10:44

Ah I see, that's awesome, can we use his attachment to fix everything then you think?
And yes we should, we don't want a bunch of random people working on it individually, we should have 1 thread, first post being constantly updated/requesting new letters and people posting bmps of all they can get. Care to make Wizz, idk how it would be best organized but it would be a great thread indeed!

pyroryan

2011-11-22 15:16:12

From: Method
Are there any requirements for the fonts (spacing, background color, symbol color, etc.)? pyroryan asked me about fonts the other day, and I'm able to grab the images for every character in every font (including some obscure ones like the fairy language font).


Yesterday I asked you. And I yield, you won while I was still refactoring stream stuff :P