;; Some important UNICODE to UTF8 conversion Functions:;;;; You'll need to purchase your copy of FastText.DLLInclude "C:Blitz3d ProjectsFastText_unicode.BB" ;; Global WhiteSquare_UTF8$ = Uni_to_UTF8$($1111) ;; ??????Type UTF8 Field byte[4] Field s$End Type UTF8sam.UTF8 = New UTF8 ;; UTF8 Sample Graphics 1024,480,32,2 Local s$ UniFont0=LoadFont("Tahoma",25) font0=LoadFont("arial.ttf",20) SetFont UniFont0 horiz = 60 ;; a horizontal placement ;; This loop prints UTF8 (unicode) characters one-at-a-time. ;; For u = $24E6 To $24FE Text horiz,40, Uni_To_UTF8(u) horiz = horiz +20 Next ;; This loop builds up a string first, and then prints them all at once ;; For u = $2730 To $274D s$ = s$ + uni_to_utf8(u) Next Text 60,70, s WaitKey():End ; This function converts a unicode value; into a UTF8 byte string;Function Uni_to_UTF8$(u) Local b1,b2,b3,b4 If (u < $80) Return Chr$(u) End If If (u < $800) b1 = ((u Shr 6) And $1f) Or $c0 b2 = (u And $3f) Or $80 Return Chr$(b1)+Chr$(b2) End If If (u<$10000) b1 = ((u Shr 12) And $0f) Or $e0 b2 = ((u Shr 6) And $3f) Or $80 b3 = (u And $3f) Or $80 Return Chr$(b1)+Chr$(b2)+Chr$(b3) End If If (u<$110000) b1 = ((u Shr 18) And $7) Or $f0 b2 = ((u Shr 12) And $3f) Or $80 b3 = ((u Shr 6) And $3f) Or $80 b4 = (u And $3f) Or $80 Return Chr$(b1)+Chr$(b2)+Chr$(b3)+Chr$(b4) End If End Function ; creates a UTF8 type from a unicode input;Function Uni_to_UTF8t.UTF8(ut.UTF8,u) Local b1,b2,b3,b4 If (u < $80) Return SetUTF8(ut,u) End If If (u < $800) b1 = ((u Shr 6) And $1f) Or $c0 b2 = (u And $3f) Or $80 Return SetUTF8(ut,b1,b2) End If If (u<$10000) b1 = ((u Shr 12) And $0f) Or $e0 b2 = ((u Shr 6) And $3f) Or $80 b3 = (u And $3f) Or $80 Return SetUTF8(ut,b1,b2,b3) End If If (u<$110000) b1 = ((u Shr 18) And $7) Or $f0 b2 = ((u Shr 12) And $3f) Or $80 b3 = ((u Shr 6) And $3f) Or $80 b4 = (u And $3f) Or $80 Return SetUTF8(ut,b1,b2,b3,b4) End If End Function Function SetUTF8.UTF8(ut.UTF8, b1=0,b2=0,b3=0,b4=0) Local s$ If ut=Null Then ut=New UTF8 utyte[1] = b1 utyte[2] = b2 utyte[3] = b3 utyte[4] = b4 For z=1 To 4 If utyte[z]=0 Then Exit s = s + utyte[z] Next uts = s Return utEnd Function
; Encoding constsConst FT_ASCII = 0Const FT_UNICODE = 1; Smooth const (LoadFont function)Const FT_DEFAULT = 0Const FT_NONANTIALIASED = 1Const FT_ANTIALIASED = 2Const FT_CLEARTYPE = 3; Horisontal align consts (X axis)Const FT_NONE = 0Const FT_LEFT = 0Const FT_CENTER = 1Const FT_RIGHT = 2; Vertical align consts (Y axis)Const FT_TOP = 0Const FT_MID = 1Const FT_MIDDLE = 1Const FT_BOTTOM = 2Const FT_BASELINE = 3; TextRect Formatting constsConst FT_NOBREAK = 256Const FT_NOCLIP = 512Const FT_CALCRECT = 1024Function LoadFont(name$="Tahoma", height=13, bold=0, italic=0, underline=0, angle#=0, smooth=FT_ANTIALIASED, encoding=FT_UNICODE) Return LoadFont_(name,height,bold,italic,underline,angle,smooth,encoding)End FunctionFunction SetFont(font) SetFont_( font )End FunctionFunction FreeFont(font) FreeFont_( font )End FunctionFunction FontWidth() Return FontWidth_()End FunctionFunction FontHeight() Return FontHeight_()End FunctionFunction Text(x, y, txt$, cx=FT_LEFT, cy=FT_TOP, encoding=FT_UNICODE) Text_(x,y,txt,cx,cy,encoding)End FunctionFunction TextRect(x, y, w, h, txt$, formatting=FT_LEFT, encoding=FT_UNICODE) Return TextRect_(x,y,w,h,txt,formatting,encoding)End FunctionFunction TextBackground(r%=-1, g%=-1, b%=-1) TextBackground_ r,g,bEnd FunctionFunction StringWidth(txt$, encoding=FT_UNICODE) Return StringWidth_(txt,encoding)End FunctionFunction StringHeight(txt$, encoding=FT_UNICODE) Return StringHeight_(txt,encoding)End Function