Author Topic: Language support  (Read 3819 times)

Offline Robert

  • Mc. Print
  • *
  • Posts: 34
    • View Profile
Language support
« on: 2013-Jan-07 »
Hello

Just began with GLbasic and I wonder if it possible to get å,ä,ö (swedish) printed with the print command. For example ö gets printed as v and even with PRINT CHR$(246),5,0,1 a get v. I understand that it can't support every language but is there mayby some trick you can use. And how is it with DDgui does it support them.   

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4030
    • View Profile
    • Space Fractal
Re: Language support
« Reply #1 on: 2013-Jan-07 »
Dont use PRINT, which is only for debugging onscreen thing. It's not very good for other uses, but instead you can measure your own drawtext function instead, using wither drawanim or polyvector. Then you would support your swedish language. I did the same trick for Greedy Mouse which could support most latin languages.
« Last Edit: 2013-Jan-07 by spacefractal »
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: Language support
« Reply #2 on: 2013-Jan-07 »
Yes it is very easy to print any character, but it takes a bit of work to set up.
The print uses a font image file, and you can use certain unused areas of the image file to make your own characters.

The first 32 character areas of the image file are "unused", and you paint you new characters into those. You will however need to print chr$(x) where x is 0 to 31. Then when you print that character, it gets its image from the location on the image file. This wont work with all character, since you cant really print them. Characters such as 9 is used for TAB, and wont print the character. 0 is NULL can may also not be printable. You will need to experiment.

How does this help you. Simply put a picture of å into one of the printable characters (background = black) and print it using that character number (x) where you put in in the image chr$(x)
The attached images show some changes I made to a font file, and the other image shows the results of the following program.

Code: (glbasic) [Select]
FOR i = 0 TO 45
PRINT CHR$(i), 10,i*10
NEXT
SHOWSCREEN
MOUSEWAIT

Edit: Remember to load the correct font image with LOADFONT
Sorry if I disagree with you spacefractal, but I use PRINT for many things, such as dynamically making buttons, changing button image text and so on.

[attachment deleted by admin]
« Last Edit: 2013-Jan-07 by backspace »
I came, I saw, I coded.

Offline Robert

  • Mc. Print
  • *
  • Posts: 34
    • View Profile
Re: Language support
« Reply #3 on: 2013-Jan-07 »
Spacefractal: I also thougt about something like that but for my project (which is a very simple chatprogram) its to much work, as Im not so used to the 2d commands yet.

Backspace: That were exactly som trick like that I had in mind. Will try it thanks.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1622
  • Particle Hawk
    • View Profile
Re: Language support
« Reply #4 on: 2013-Jan-07 »
The builtin font creator has an option for 256 characters.
See screenshot below, though i never used the extended character set so i cant tell you if GLBasic is bugged with this or not.

If for whatever reason you cannot access these characters with the GLBasic PRINT command, perhaps this is a bug and a report should be posted, or we can move the topic there.


[attachment deleted by admin]
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4030
    • View Profile
    • Space Fractal
Re: Language support
« Reply #5 on: 2013-Jan-07 »
PRINT did not work very well for Greedy Mouse due that way its scaling its graphics. But giving you idea, here some code:

Code: (glbasic) [Select]
FUNCTION PaintText$: txt$, color#, x, y, xspot=-1, yspot=-1, alpha=1, zoom#=-1
STATIC font$="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890:/-._?@,ÀÁÂÃÄÅÆÈÉÊËÌÍÎÏŸÑŠŽÐÒÓÔÕÖØÙÚÛÜÞߌÝÇ"
STATIC aceii[] AS ExtCol
STATIC created=0
LOCAL fontsize=46
LOCAL txt2$=txt$
LOCAL notstranslate=0

IF zoom#<0.05 THEN RETURN

alpha=1

LOCAL txt2$=""

IF LEFT$(txt$, 1)<>"&"
IF LEFT$(txt$, 2)="**"
txt$=UCASE$(RIGHT$(txt$, LEN(txt$)-2))
txt2$=txt$
ELSEIF LEFT$(txt$, 1)<>"*"
txt$=LEFT$(txt$, 3)
txt$=GetStr$(txt$, "lan")
IF txt$="" THEN txt$=txt2$
txt$=UCASE$(txt$)
ELSE
txt$=RIGHT$(txt$, LEN(txt$)-1)
ENDIF
IF txt2$="" THEN txt2$=StringField$(txt$, 2, "|")
IF txt2$<>"" THEN txt$=StringField$(txt$, 1, "|")
ELSE
txt$=UCASE$(RIGHT$(txt$, LEN(txt$)-1))
txt2$=txt$
notstranslate=1
ENDIF
IF PLATFORMINFO$("")="IPHONE" OR SETTING_DETAILS<2
IF S_Status$="Play" AND SHOWTEXT=0 THEN color#=RGB(255, 255, 255)
ENDIF
IF created=0
created=1
fontid=imageGet("font")
DIM aceii[256]
LOCAL x=0, y=0
FOR i=0 TO LEN(font$)
LOCAL b=ASC(MID$(font$, i, 1))
aceii[b].l=i
aceii[b].x=x
aceii[b].y=y
x=x+46;
IF x>46*11-5
x=0
y=y+fontsize
ENDIF
NEXT
ENDIF

LOCAL i,XX, YY, WW, HH
// some alpha code in that way I prefer. Not a issue in the real alphamode, its just me :-D

LOCAL h#=50 //*zoom#
LOCAL w#=LEN(txt$)*50 //*zoom#

// math placement for hotspots
IF xspot=-1 THEN PX=x#
IF xspot=0 THEN PX=ScreenWidth/2.0-(w#*zoom#/2.0)+x#
IF xspot=1 THEN PX=ScreenWidth-w#*zoom#-x#
IF yspot=-1 THEN PY=y#
IF yspot=0 THEN PY=ScreenHeight/2.0-(h*zoom#/2.0)+y#
IF yspot=1 THEN PY=ScreenHeight-h#*zoom#-y#
PW=w
PH=h

IF txt2$<>"" AND notstranslate=0 THEN PY=PY-50*zoom#
IF device$<>"ipad" AND SETTING_DETAILS=2
SetAlphaMode(alpha)
ELSE
SetAlphaMode(1)
ENDIF
LOCAL size=INTEGER(50*zoom)
LOCAL fsize=50
LOCAL tasc=0
//txt$=txt$
SMOOTHSHADING TRUE
IF fontsize<30 THEN SMOOTHSHADING FALSE

FOR i=0 TO LEN(txt$)-1
tasc=ASC(MID$(txt$, i, 1))
IF tasc<>32
IF i>0 THEN POLYNEWSTRIP
POLYVECTOR PX+size, PY, aceii[tasc].x+fontsize, aceii[tasc].y, color
POLYVECTOR PX, PY, aceii[tasc].x, aceii[tasc].y, color
POLYVECTOR PX+size, PY+size, aceii[tasc].x+fontsize, aceii[tasc].y+fontsize, color
POLYVECTOR PX, PY+size, aceii[tasc].x, aceii[tasc].y+fontsize, color
ENDIF
IF S_Status$<>"Help"
PX=PX+size
ELSE
PX=PX+size/1.2
ENDIF
NEXT
SMOOTHSHADING TRUE
IF txt2$<>"" THEN RETURN txt2$
RETURN ""
ENDFUNCTION

Code: (glbasic) [Select]
STARTPOLY fontid, 2
PaitText$("stars:", RGB(255, 255, 255), score1.x, score1.y, score1.alignx, score1.aligny, 0.8, SCALING#); //POLYNEWSTRIP
ENDPOLY
The above code is as used in Greedy Mouse, its of course not perfect (due its uses some features that is not there), but its should give you ideas to create your own PRINT function.

PS. but this this can been a bug, so its nice to move its to the bug forum :-D, but I still recommered to write your own really.
« Last Edit: 2013-Jan-07 by spacefractal »
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1137
    • View Profile
    • My GLBasic code archiv
Re: Language support
« Reply #6 on: 2013-Jan-07 »
I cant understand why PRINT has such a bad reputation, it works pretty well and is even more useful since it got kerning. Of cause a own font can do more things like font size scaling and different colours, but thats more than small projects need and can be done with some tricks too.
If you want to improve your fonts (e.g. replace chars...) use blastars awesome font creator, that should be included in GLB IMHO: http://www.glbasic.com/forum/index.php?topic=6421.0
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1622
  • Particle Hawk
    • View Profile
Re: Language support
« Reply #7 on: 2013-Jan-07 »
@robert:

Im not able to find any bug.
Here is a sample project which demonstrates the use of the 255 acsii codes using native GLBasic print.

Code: (glbasic) [Select]
FOR i = 0 TO 255
PRINT CHR$(i) ,COS(i*4)*i+320,SIN(i*4)*i+240
NEXT

SHOWSCREEN
KEYWAIT
END


The full project is attached to this message below the screenshot:


[attachment deleted by admin]
« Last Edit: 2013-Jan-07 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Robert

  • Mc. Print
  • *
  • Posts: 34
    • View Profile
Re: Language support
« Reply #8 on: 2013-Jan-07 »
Hemlos:

You have absolutely right I had just missed that I could mark 256 characters. Now I can use this function for my simple chatt program but for other projects I have got some nice idées. Thanks all

« Last Edit: 2013-Jan-07 by Robert »

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4030
    • View Profile
    • Space Fractal
Re: Language support
« Reply #9 on: 2013-Jan-07 »
mightbeen 256 chars should been enabled by defaults? Its more often we need to use more than those 128 chars? I have wonder that too.

personally PRINT is a great command for debug things and did use that too, but just not in the case in my game due direct scaling was required. Its was too ugly.

And yes that tool linked should been included in v11 official, but hopefully we see a english version too. Its looks very awesome, but its just in german.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1137
    • View Profile
    • My GLBasic code archiv
Re: Language support
« Reply #10 on: 2013-Jan-07 »
The tool is already in english, just load it and test.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10851
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Language support
« Reply #11 on: 2013-Jan-17 »
The new dingsfont on the forums can make smooth fonts with alphamode -1 enabled.