It has been a while since I registered here. Yesterday I finally managed to make my first PureBasic [console] application.
For the past years I've been doing lots of programming in Windows .bat so I have one .bat that has few thousands of lines. One of the tasks this app can do is it generates a special stream file (binary values 0x00 ... 0xff are created and written with pure .bat (see dostips.com for more info)..
I generate these files for a 3rd party application that displays some information from these files but with TrueType fonts. First image shows the correct number of capital letter 'I' and the next image shows that there is one character too many.
Same goes for capital letter 'M':
Looks like the total width of the usable sreen is 455 pixels (window cannot be resized). So I PrtScreened all the characters and created a table with characters' widths.
So to avoid this I decided to use only first 40 characters from the string but this causes that there is usually lots of trailing spaces.
So I added a code to calculate all the characters lengths so I would maximize the line displayed. Everything works great but it is very sloooow. I wrote a COBOL* program to calculate the lenghts and it is now a little better (this is very old pure DOS MS COBOL 5.0 - so 16-bit exectuable is build). So I decided I will try and do it PureBasic. And here I need your help.
Code: Select all
OpenConsole()
OpenFile (0, "input_file.txt", #PB_Ascii)
CreateFile(1,"output_file.txt",#PB_Ascii)
Label11:
If Eof (0) = 1
Goto end
EndIf
niz$=ReadString (0)
sum.w=0
offset_cnt.w=1
Label00:
tmp_char$=Mid(niz$,offset_cnt.w,1)
tt_chr_len.w=13
If Asc(tmp_char$)=32
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=33
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=34
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=35
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=36
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=37
tt_chr_len.w=15
EndIf
If Asc(tmp_char$)=38
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=39
tt_chr_len.w=3
EndIf
If Asc(tmp_char$)=40
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=41
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=42
tt_chr_len.w=7
EndIf
If Asc(tmp_char$)=43
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=44
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=45
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=46
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=47
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=48
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=49
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=50
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=51
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=52
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=53
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=54
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=55
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=56
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=57
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=58
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=59
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=60
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=61
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=62
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=63
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=64
tt_chr_len.w=17
EndIf
If Asc(tmp_char$)=65
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=66
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=67
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=68
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=69
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=70
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=71
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=72
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=73
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=74
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=75
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=76
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=77
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=78
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=79
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=80
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=81
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=82
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=83
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=84
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=85
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=86
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=87
tt_chr_len.w=17
EndIf
If Asc(tmp_char$)=88
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=89
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=90
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=91
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=92
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=93
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=94
tt_chr_len.w=7
EndIf
If Asc(tmp_char$)=95
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=96
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=97
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=98
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=99
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=100
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=101
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=102
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=103
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=104
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=105
tt_chr_len.w=4
EndIf
If Asc(tmp_char$)=106
tt_chr_len.w=3
EndIf
If Asc(tmp_char$)=107
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=108
tt_chr_len.w=3
EndIf
If Asc(tmp_char$)=109
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=110
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=111
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=112
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=113
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=114
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=115
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=116
tt_chr_len.w=4
EndIf
If Asc(tmp_char$)=117
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=118
tt_chr_len.w=7
EndIf
If Asc(tmp_char$)=119
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=120
tt_chr_len.w=7
EndIf
If Asc(tmp_char$)=121
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=122
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=123
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=124
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=125
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=126
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=127
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=128
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=129
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=130
tt_chr_len.w=4
EndIf
If Asc(tmp_char$)=131
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=132
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=133
tt_chr_len.w=17
EndIf
If Asc(tmp_char$)=134
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=135
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=136
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=137
tt_chr_len.w=17
EndIf
If Asc(tmp_char$)=138
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=139
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=140
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=141
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=142
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=143
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=144
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=145
tt_chr_len.w=4
EndIf
If Asc(tmp_char$)=146
tt_chr_len.w=4
EndIf
If Asc(tmp_char$)=147
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=148
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=149
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=150
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=151
tt_chr_len.w=17
EndIf
If Asc(tmp_char$)=152
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=153
tt_chr_len.w=17
EndIf
If Asc(tmp_char$)=154
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=155
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=156
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=157
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=158
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=159
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=160
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=161
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=162
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=163
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=164
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=165
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=166
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=167
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=168
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=169
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=170
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=171
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=172
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=173
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=174
tt_chr_len.w=13
EndIf
If Asc(tmp_char$)=175
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=176
tt_chr_len.w=7
EndIf
If Asc(tmp_char$)=177
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=178
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=179
tt_chr_len.w=3
EndIf
If Asc(tmp_char$)=180
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=181
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=182
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=183
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=184
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=185
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=186
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=187
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=188
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=189
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=190
tt_chr_len.w=4
EndIf
If Asc(tmp_char$)=191
tt_chr_len.w=8
EndIf
If Asc(tmp_char$)=192
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=193
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=194
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=195
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=196
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=197
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=198
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=199
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=200
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=201
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=202
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=203
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=204
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=205
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=206
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=207
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=208
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=209
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=210
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=211
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=212
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=213
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=214
tt_chr_len.w=12
EndIf
If Asc(tmp_char$)=215
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=216
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=217
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=218
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=219
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=220
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=221
tt_chr_len.w=11
EndIf
If Asc(tmp_char$)=222
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=223
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=224
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=225
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=226
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=227
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=228
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=229
tt_chr_len.w=3
EndIf
If Asc(tmp_char$)=230
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=231
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=232
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=233
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=234
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=235
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=236
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=237
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=238
tt_chr_len.w=5
EndIf
If Asc(tmp_char$)=239
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=240
tt_chr_len.w=10
EndIf
If Asc(tmp_char$)=241
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=242
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=243
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=244
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=245
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=246
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=247
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=248
tt_chr_len.w=6
EndIf
If Asc(tmp_char$)=249
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=250
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=251
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=252
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=253
tt_chr_len.w=9
EndIf
If Asc(tmp_char$)=254
tt_chr_len.w=4
EndIf
If Asc(tmp_char$)=255
tt_chr_len.w=6
EndIf
sum.w=sum.w+tt_chr_len.w
If sum.w>450
PrintN ("sum " + sum)
PrintN ("offset_cnt " + offset_cnt)
WriteString(1,Str(offset_cnt))
Goto label11
EndIf
offset_cnt.w=offset_cnt.w + 1
Goto Label00
end:
CloseFile (0)
CloseFile (1)
Input()
So my question is: how can 'if' part of the code be optimized (dim array)?
I need:
Code: Select all
if asc(character)=32 then truetype_font_character_length=5 in more efficient way.
Saso
(this is a temporary solution to skip the .bat part of calculating the required offset of input string - so why there are input and output file. Please focus only to the 'if' part. Thanks.
This table shows all the lengths for decimal values 32...255 if it is of any help (to import to a table or something - just first replace ### with required code, then ## and so on). For example: space (dec 32) has length of 5 pixels.
Code: Select all
#032##5###
#033##5###
#034##6###
#035##9###
#036##9###
#037##15###
#038##11###
#039##3###
#040##6###
#041##6###
#042##7###
#043##10###
#044##5###
#045##6###
#046##5###
#047##5###
#048##9###
#049##9###
#050##9###
#051##9###
#052##9###
#053##9###
#054##9###
#055##9###
#056##9###
#057##9###
#058##5###
#059##5###
#060##10###
#061##10###
#062##10###
#063##9###
#064##17###
#065##11###
#066##11###
#067##12###
#068##12###
#069##11###
#070##10###
#071##12###
#072##11###
#073##5###
#074##9###
#075##11###
#076##9###
#077##13###
#078##11###
#079##12###
#080##11###
#081##12###
#082##11###
#083##11###
#084##9###
#085##11###
#086##11###
#087##17###
#088##11###
#089##11###
#090##9###
#091##5###
#092##5###
#093##5###
#094##7###
#095##9###
#096##6###
#097##9###
#098##9###
#099##9###
#100##9###
#101##9###
#102##5###
#103##9###
#104##9###
#105##4###
#106##3###
#107##9###
#108##3###
#109##13###
#110##9###
#111##9###
#112##9###
#113##9###
#114##6###
#115##8###
#116##4###
#117##9###
#118##7###
#119##11###
#120##7###
#121##9###
#122##8###
#123##6###
#124##5###
#125##6###
#126##10###
#127##13###
#128##9###
#129##13###
#130##4###
#131##13###
#132##6###
#133##17###
#134##9###
#135##9###
#136##13###
#137##17###
#138##11###
#139##6###
#140##11###
#141##9###
#142##9###
#143##9###
#144##13###
#145##4###
#146##4###
#147##6###
#148##6###
#149##6###
#150##9###
#151##17###
#152##13###
#153##17###
#154##8###
#155##6###
#156##8###
#157##6###
#158##8###
#159##8###
#160##5###
#161##6###
#162##6###
#163##9###
#164##9###
#165##11###
#166##5###
#167##9###
#168##6###
#169##13###
#170##11###
#171##9###
#172##10###
#173##6###
#174##13###
#175##9###
#176##7###
#177##9###
#178##6###
#179##3###
#180##6###
#181##9###
#182##9###
#183##5###
#184##6###
#185##9###
#186##8###
#187##9###
#188##9###
#189##6###
#190##4###
#191##8###
#192##11###
#193##11###
#194##11###
#195##11###
#196##11###
#197##9###
#198##12###
#199##12###
#200##12###
#201##11###
#202##11###
#203##11###
#204##11###
#205##5###
#206##5###
#207##12###
#208##12###
#209##11###
#210##11###
#211##12###
#212##12###
#213##12###
#214##12###
#215##10###
#216##11###
#217##11###
#218##11###
#219##11###
#220##11###
#221##11###
#222##9###
#223##10###
#224##6###
#225##9###
#226##9###
#227##9###
#228##9###
#229##3###
#230##9###
#231##9###
#232##9###
#233##9###
#234##9###
#235##9###
#236##9###
#237##5###
#238##5###
#239##10###
#240##10###
#241##9###
#242##9###
#243##9###
#244##9###
#245##9###
#246##9###
#247##9###
#248##6###
#249##9###
#250##9###
#251##9###
#252##9###
#253##9###
#254##4###
#255##6###
* some background: I have experience with: ZX Spectrum BASIC, SHARP Pocket Computer Basic, Z80A assembler, SC61860 assembled, COBOL (MS-DOS and VAX/VMS), Visual Basic 6.0... maybe some more. I only have licensed MS COBOL 5.0 for pure MS-DOS (in a virtual machine) so I was forced to use it. And now I found PureBasic... I think I will register very soon...